<template>
  <el-container>
    <basic-crud :option="option" apiGetListUrl="/msg/messageController/listMyUnReadMsg"
                :fastSearch="{name:'消息标题、工号',fastColumn:'title,sendUserCode'}">
      <template #title="{ row }">
        <el-link type="primary" @click="linkClickHandler(row)">{{ row.title }}</el-link>
      </template>
    </basic-crud>
  </el-container>
</template>

<script setup>
import {useRouter} from "vue-router";

const router = useRouter()
const option = ref({
  highlightCurrentRow: true,
  addBtn: false,
  menu: false,
  size: 'small',
  column: [
    {
      label: "类型",
      prop: "msgClassifyText",
      sortable: true,
      width: 100,
    },
    {
      label: "消息标题",
      prop: "title",
      search: true,
      minWidth: 400,
      sortable: true,
      searchSpan: 6,
      overHidden: true,
      slot: true,
    },
    {
      label: "发送时间",
      prop: "sendTime",
      width: 140,
      type: 'datetime',
      overHidden: true,
      formatter: (row) => {
        return row.sendTime.substring(0,16);
      },
      sortable: true,
      slot: true
    },
    {
      label: '工号',
      prop: "sendUserCode",
      searchLabelWidth: 100,
      search: true,
      sortable: true,
      searchSpan: 6,
      width: 130,
    },
    {
      label: "发送人姓名",
      prop: "sendUserName",
      searchLabelWidth: 100,
      search: true,
      searchSpan: 6,
      sort: true,
      width: 130,
    },
    {
      label: "内容",
      overHidden: true,
      prop: "msgContent",
      minWidth: 300
    },
  ]
});

const linkClickHandler = (row) => {
  if (row.msgLink != null && row.msgLink != '') {
    var link = row.msgLink.replace("inner:", "").replace("?", "").split("&");
    var html = link.find((val => (val.toLowerCase().startsWith("html=") || val.toLowerCase().startsWith("html ="))));
    if (html != null && html != '') {
      var page = html.split("=")[1].replace("-", "/");
      var single = {
        fromUndo: true
      };
      link.forEach((val) => {
        var temp = val.split("=");
        single[temp[0]] = temp[1];
      });
      router.push({
        path: "/" + page,
        query: single
      })
    }
  }
};
</script>

<style lang='scss' scoped>

</style>
